// util.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "util.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// The one and only application object

CWinApp theApp;

using namespace std;

#include "common_park.h"

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
	// initialize MFC and print and error on failure
	if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
	{
		// TODO: change error code to suit your needs
		_tprintf(_T("Fatal Error: MFC initialization failed\n"));
		return 1;
	}

	CString filePath = _T("c:\\2\\33\\1.hwp");

	bool aaa2 = FileUtils::IsExistFolder(L"c:\\11\\");
	bool aaa = FileUtils::IsExistFolder(L"c:\\Windows\\");

	bool aaa1 = FileUtils::IsExistFolder(L"c:\\111\\");

	


	printf("%s\n", CT2A(FileUtils::GetExtName(filePath).GetBuffer(MAX_PATH)));
	printf("%s\n", CT2A(FileUtils::GetOnlyFileName(filePath).GetBuffer(MAX_PATH)));
	printf("%s\n", CT2A(FileUtils::GetFileName(filePath).GetBuffer(MAX_PATH)));
	printf("%s\n", CT2A(FileUtils::GetFileDirectory(filePath).GetBuffer(MAX_PATH)));

	printf("%s\n", CT2A(FileUtils::GetProgramPath()));

	CString tmpString = _T("park;se;chul");
	CString tmpSplit = _T(";");

	CStringArray tmpArray;

	int count = stringUtils::SplitString(tmpString, tmpSplit, tmpArray);
	printf("count = %d\n", count);

	int size = tmpArray.GetSize();

	for (int i = 0; i < size; i++) {
		printf("%s\n", CT2A(tmpArray.GetAt(i)));
	}
	
	CString tmpDirectory = _T("d:/test\\aaa");
	FileUtils::MakeDirectory(tmpDirectory);
	
	CString copySrcFile = _T("D:\\1\\1");
	CString copyDstFile = _T("D:\\1\\2");
	FileUtils::copyDirectory(copySrcFile, copyDstFile);
	FileUtils::DeleteDirectory(copyDstFile);

	printf("%s\n", CT2A(FileUtils::randomString(20).GetBuffer()));
	printf("%s\n", CT2A(FileUtils::randomString(20).GetBuffer()));
	printf("%s\n", CT2A(FileUtils::randomString(20).GetBuffer()));
	printf("%s\n", CT2A(FileUtils::randomString(20).GetBuffer()));
	printf("%s\n", CT2A(FileUtils::randomString(20).GetBuffer()));
	
	CStringArray testArray;
	for (int i = 0; i < 10; i++) {
		testArray.Add(FileUtils::randomString(i));
	}
	/*
	fileReadWrite write;
	write.setInfo(_T("d:\\1\\1.txt"), _T("UTF-8"));
	write.fileWrite(testArray);
	*/

	
	bool bRet = FileUtils::writeTextFile(_T("C:\\1.txt"), testArray, CP_UTF8);

	CStringArray readArray;

	bRet = FileUtils::readTextFile(_T("C:\\1.txt"), readArray, CP_UTF8);

	int a = 0;

	printf("==================\n");

	for(int i =0 ; i < testArray.GetSize() ; i++)
	{
		CString aaa = testArray.GetAt(i);

		printf("%s\n", CT2A(aaa.GetBuffer()));
	}
	printf("==================\n");


	for(int i = 0 ; i < readArray.GetSize() ; i++)
	{
		CString aaa = readArray.GetAt(i);

		printf("%s\n", CT2A(aaa.GetBuffer()));

	}
	


	return 0;
}
